package com.xjrsoft.module.customer.erp_model.erp_inventoryManage.controller;

import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.utils.DataTransUtil;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.customer.erp_model.erp_inventoryManage.dto.ErpInventoryDto;
import com.xjrsoft.module.customer.erp_model.erp_inventoryManage.dto.SaveErpInventoryFormDataDto;
import com.xjrsoft.module.customer.erp_model.erp_inventoryManage.vo.ErpInventoryVo;
import com.xjrsoft.module.customer.erp_model.erp_inventoryManage.vo.ErpInventoryListVo;
import com.xjrsoft.module.customer.erp_model.erp_inventoryManage.dto.ErpInventoryListDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import com.xjrsoft.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customer.erp_model.erp_inventoryManage.entity.ErpInventory;
import com.xjrsoft.module.customer.erp_model.erp_inventoryManage.service.IErpInventoryService;

/**
 *  控制器
 *
 * @author pp
 * @since 2021-10-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("/erp_inventorymanage")
@Api(value = "库存管理", tags = "库存管理接口")
public class ErpInventoryController {


	private final IErpInventoryService erpInventoryService;


	/**
	 * 详情
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入erpInventory")
	public Response<ErpInventoryVo> getFormData(@PathVariable String id) {
		// 主表数据
		ErpInventory erpInventory = erpInventoryService.getById(id);
		return Response.ok(BeanUtil.copy(erpInventory, ErpInventoryVo.class));
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入erpInventory")
	public Response<PageOutput<ErpInventoryListVo>> getPageList(ErpInventoryListDto listDto) {
		PageOutput<ErpInventoryListVo> page = erpInventoryService.getPageList(listDto);
//		List<ErpInventoryListVo> records = BeanUtil.copyList(page.getRecords(), ErpInventoryListVo.class);
		// 转换列表数据
		DataTransUtil.transListShowData(page.getRows());
		// 工作流数据处理
		//FlowableUtil.systemFormList(records, SecureUtil.getModuleId());
		return Response.ok(page);
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入erpInventory")
	public Response save(@RequestBody SaveErpInventoryFormDataDto formDto) {
		ErpInventoryDto erpInventoryDto = formDto.getErpInventoryDto();
		ErpInventory erpInventory = BeanUtil.copy(erpInventoryDto, ErpInventory.class);
		String dataId = erpInventoryService.addErpInventory(erpInventory);
		return dataId == null ? Response.notOk() : Response.ok(dataId);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入erpInventory")
	public Response update(@PathVariable String id, @RequestBody SaveErpInventoryFormDataDto formDto) {
		ErpInventoryDto erpInventoryDto = formDto.getErpInventoryDto();
		ErpInventory erpInventory = BeanUtil.copy(erpInventoryDto, ErpInventory.class);
		return Response.status(erpInventoryService.updateErpInventory(id, erpInventory));
	}


	
	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(erpInventoryService.removeByIds(Func.toStrList(ids)));
	}

	
}
